package Operations;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        //借阅图书
        System.out.println("借阅图书！");
        System.out.println("请输入你要借阅图书的名字：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int size = bookList.getNumBook();
        for (int i = 0; i < size; i++) {
            Book book = bookList.getpos(i);
            if (name.equals(book.getBookname())) {
                if (book.isBorrow()) {
                    System.out.println("该书已经被借走了！");
                    return;
                } else {
                    book.setBorrow(true);
                    System.out.println("借阅图书成功");
                    return;
                }
            }
            System.out.println("没有你要借阅的图书！");
        }
    }
}
